package com.sx.wechat.command.api;

import com.sx.core.mybatis.SessionTemplate;
import com.sx.core.vo.JsonReaderResponse;
import com.sx.wechat.command.cmd.AbstractCommand;
import com.sx.wechat.security.AuthenticationHolder;
import com.sx.wechat.security.Principal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 挂失解挂
 * Created by lihao on 2018/3/21.
 */
@Component("last_order_his")
public class Last_order_his extends AbstractCommand {
    @Autowired
    JdbcTemplate jdbcTemplate;
    @Autowired
    SessionTemplate sessionTemplate;

    @Override
    public Object executeApi(HttpServletRequest request, HttpServletResponse response) {
        Principal principal= AuthenticationHolder.getCurrent();
        List<Map<String,Object>> last_order=jdbcTemplate.queryForList("SELECT * FROM t_order WHERE teacherid=? ORDER BY time DESC limit 1",principal.getId());
        if(last_order.isEmpty()){
            return new JsonReaderResponse();
        }
        List<Map<String,Object>> list=jdbcTemplate.queryForList("select \n" +
                "i.id,s.score,i.name,i.sno,i.sex,i.idno\n" +
                "from t_order_rec_stu rs\n" +
                "left join t_information i on rs.stuid=i.id\n" +
                "left JOIN t_all_score s on rs.stuid=s.stuid\n" +
                "where rs.orderid=?",last_order.get(0).get("id"));
        return new JsonReaderResponse(list).addExtra(last_order.get(0));

    }

}
